/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;

/**
 *
 * @author Dragan
 */
public class Condition implements Serializable {

    public enum Predicate {

        Equal, Range
    };
    private Atribute atribute;
    // 0.0 <= selectivity <= 1.0
    private double selectivity;
    private Predicate predicate;

    public Condition(Atribute atribute, Predicate predicate) {
        this.atribute = atribute;
        this.predicate = predicate;
        try {
            switch (predicate) {
                case Equal:
                    selectivity = 1 / (double) atribute.getTable().getNumberOfTuples();
                    break;
                case Range:
                    selectivity = 0.5;
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public Predicate getPredicate() {
        return predicate;
    }

    public Atribute getAtribute() {
        return atribute;
    }

    public double getSelectivity() {
        return selectivity;
    }

    @Override
    public String toString() {
        String str = atribute.getName();
        str += predicate == Predicate.Equal ? "=" : "<>";
        return str;
    }
}
